<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
	<button>get</button>
	<button>post</button>
</body>
<script>
	const btns = document.querySelectorAll("button");
	btns[0].onclick = function(){
		const xhr = new XMLHttpRequest();
		xhr.responseType = "json";// text document
		xhr.open("get","http://zhangpeiyue.com/scoreList?id=1");
		xhr.send();
		xhr.onload = function(){
			console.log(xhr.response);
			// console.log(JSON.parse(xhr.response))
		}
	}
	btns[1].onclick = function(){
		const xhr = new XMLHttpRequest();
		xhr.responseType = "json";
		xhr.open("post","http://zhangpeiyue.com/scoreList");
		xhr.setRequestHeader("Content-Type","application/json");
		xhr.send(JSON.stringify({
			userName:"高启强",
			age:12
		}));
		xhr.onload = function(){
			console.log(xhr.response);
		}
	}
</script>
</html>